clear;
clc;
N=64;
A_noh=diag(2*ones(N,1))-diag(1*ones(N-1,1),1)-diag(1*ones(N-1,1),-1);
I=eye(N);
Z=zeros(1,N);
h=1/N;
j=1:N;
k=64;
iteration=zeros(N-1,2);
w=[1;2/3];
a = 1:63;
figure(1);
for l=1:2
Tw=I-(w(l)/2)*A_noh;
for k=1:N-1
omega=sin(j*k*pi*h)';
flag=0;
err_rel=0;
temp1=omega;
omega_norm=norm(omega);
while(err_rel<100 && flag<300)
    temp1=Tw*temp1;
    err_rel=omega_norm/norm(temp1);
   flag=flag+1; 
end
iteration(l,k)=flag;
end
end
b=iteration(1,:);
values = spcrv([[a(1) a a(end)];[b(1) b b(end)]],3);
plot(values(1,:),values(2,:),'r-');
hold on;
b=iteration(2,:);
values = spcrv([[a(1) a a(end)];[b(1) b b(end)]],3);
plot(values(1,:),values(2,:),'b-.');
hold on;
y=0:300;
x=16*ones(1,301);
plot(x,y,'k');
hold on;
x=3*x;
plot(x,y,'c');
hold on;
legend('w=1','w=2/3','x=16','x=48'),xlabel('k'),ylabel('Iterations'),title('Weighted Jacobi method with ω = 1 and ω = 2/3'),grid on;
saveas(1,'927Interations.png');



